// 自动处理 JWT Token 的 Knife4j 插件
(function() {
    // 监听登录请求，自动保存 Token
    window.addEventListener('knife4j.request.success', function(event) {
        if (event.detail.url.endsWith('/auth/login')) {
            const token = event.detail.response.data.token;
            localStorage.setItem('jwt_token', token);
            console.log('Token saved:', token);
        }
    });

    // 自动为每个请求添加 Token
    window.knife4j = window.knife4j || {};
    window.knife4j.beforeSend = function(config) {
        const token = localStorage.getItem('jwt_token');
        if (token) {
            config.headers['Authorization'] = 'Bearer ' + token;
        }
        return config;
    };
})();